//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "ZeroYieldStructure.h"
using namespace Cephei::QL::Termstructures::Yield;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/InterestRate.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (boost::shared_ptr<QuantLib::ZeroYieldStructure>& childNative, Object^ owner) : CYieldTermStructure(CZeroYieldStructure::typeid)
{
#ifdef HANDLE
	_phZeroYieldStructure = NULL;
#endif
	_ppZeroYieldStructure = &childNative;
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppZeroYieldStructure));
}
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (QuantLib::ZeroYieldStructure& childNative, Object^ owner) : CYieldTermStructure(CZeroYieldStructure::typeid)
{
#ifdef HANDLE
	_phZeroYieldStructure = NULL;
#endif
	_ppZeroYieldStructure = new boost::shared_ptr<QuantLib::ZeroYieldStructure> (&childNative);
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppZeroYieldStructure));
    _ZeroYieldStructureOwner = owner;
    _YieldTermStructureOwner = owner;
}

Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (CZeroYieldStructure^ copy) : CYieldTermStructure(CZeroYieldStructure::typeid)
{
#ifdef HANDLE
	_phZeroYieldStructure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppZeroYieldStructure = new boost::shared_ptr<QuantLib::ZeroYieldStructure> (copy->GetShared());
        _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppZeroYieldStructure));
    }
}
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (System::Type^ t) : CYieldTermStructure(CZeroYieldStructure::typeid)
{
#ifdef HANDLE
	_phZeroYieldStructure = NULL;
#endif
	if (!t->IsSubclassOf(CZeroYieldStructure::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (QuantLib::Handle<QuantLib::ZeroYieldStructure>& childNative, Object^ owner)  : CYieldTermStructure(CZeroYieldStructure::typeid)
{
	_phZeroYieldStructure = &childNative;
	_ppZeroYieldStructure = &static_cast<boost::shared_ptr<QuantLib::ZeroYieldStructure>>(childNative.currentLink());
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppZeroYieldStructure));
    _ZeroYieldStructureOwner = owner;
}
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (QuantLib::Handle<QuantLib::ZeroYieldStructure> childNative)  : CYieldTermStructure(CZeroYieldStructure::typeid)
{
	_phZeroYieldStructure = &childNative;
	_ppZeroYieldStructure = &static_cast<boost::shared_ptr<QuantLib::ZeroYieldStructure>>(childNative.currentLink());
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppZeroYieldStructure));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::CZeroYieldStructure (QuantLib::ZeroYieldStructure childNative)  : CYieldTermStructure(CZeroYieldStructure::typeid)
{
#ifdef HANDLE
	_phZeroYieldStructure = NULL;
#endif
	_ppZeroYieldStructure = new boost::shared_ptr<QuantLib::ZeroYieldStructure> (new QuantLib::ZeroYieldStructure (childNative));
    _ppYieldTermStructure = new boost::shared_ptr<QuantLib::YieldTermStructure> (boost::dynamic_pointer_cast<QuantLib::YieldTermStructure> (*_ppZeroYieldStructure));
}
#endif

Cephei::QL::Termstructures::Yield::CZeroYieldStructure::~CZeroYieldStructure ()
{
    if (_ppZeroYieldStructure != NULL)
    {
	    delete _ppZeroYieldStructure;
        _ppZeroYieldStructure = NULL;
    }
}
Cephei::QL::Termstructures::Yield::CZeroYieldStructure::!CZeroYieldStructure ()
{
    if (_ppZeroYieldStructure != NULL)
    {
	    delete _ppZeroYieldStructure;
    }
}
QuantLib::ZeroYieldStructure& Cephei::QL::Termstructures::Yield::CZeroYieldStructure::GetReference ()
{
    if (_ppZeroYieldStructure == NULL) throw gcnew NativeNullException ();
	return **_ppZeroYieldStructure;
}
boost::shared_ptr<QuantLib::ZeroYieldStructure>& Cephei::QL::Termstructures::Yield::CZeroYieldStructure::GetShared ()
{
    if (_ppZeroYieldStructure == NULL) throw gcnew NativeNullException ();
	return *_ppZeroYieldStructure;
}
QuantLib::ZeroYieldStructure* Cephei::QL::Termstructures::Yield::CZeroYieldStructure::GetPointer ()
{
    if (_ppZeroYieldStructure == NULL) throw gcnew NativeNullException ();
	return &**_ppZeroYieldStructure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ZeroYieldStructure>& Cephei::QL::Termstructures::Yield::CZeroYieldStructure::GetHandle ()
{
	if (_phZeroYieldStructure == NULL)
	{
		_phZeroYieldStructure = new Handle<QuantLib::ZeroYieldStructure> (*_ppZeroYieldStructure);
	}
	return *_phZeroYieldStructure;
}
#endif
bool Cephei::QL::Termstructures::Yield::CZeroYieldStructure::HasNative () 
{
	return (_ppZeroYieldStructure != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

